//
//  SPPartnerInfoViewController.m
//  SuperPatrner
//
//  Created by EvanZ on 15/3/15.
//  Copyright (c) 2015年 EvanZ. All rights reserved.
//

#import "SPPartnerInfoViewController.h"
#import "SPHTTPRequestOperationManager.h"
#import "SPSecondPartnerInfoViewController.h"
#import "Methods.h"

@interface SPPartnerInfoViewController (){
    UISegmentedControl * m_segmentControl;
    UILabel * m_partnerInfoLable;
    UILabel * m_firstPartnerInfoLable;
    UILabel * m_secondPartnerInfoLable;
    UIView * m_firstPartnerView;
    UIView * m_secondPartnerView;
    UITableView * m_partnerTableView;
    NSMutableArray * m_itemMutableArray;
    
    UIView * m_userInfoView;
    UILabel * m_titleLabel;
    UIImageView * m_avatarImageView;
    UILabel * m_userInfoTextLabel;
    UILabel * m_rankInfoLabel;
    UILabel * m_signinTextLabel;
    UILabel * m_signinInfoTextLabel;
    UILabel * m_detailTextLabel;
    UILabel * m_detailInfoTextLabel;
    
    UILabel * m_firstPartnerAmountInfoLabel;
    UILabel * m_firstPartnerInInfoLabel;
    UILabel * m_firstPartnerOutInfoLabel;
    UILabel * m_firstPartnerIn2InfoLabel;
    UILabel * m_firstPartnerOut2InfoLabel;
    UILabel * m_firstPartnerContributionInfoLabel;
    
    UILabel * m_secondPartnerAmountInfoLabel;
    UILabel * m_secondPartnerInInfoLabel;
    UILabel * m_secondPartnerOutInfoLabel;
    UILabel * m_secondPartnerIn2InfoLabel;
    UILabel * m_secondPartnerOut2InfoLabel;
    UILabel * m_secondPartnerContributionInfoLabel;
}

@end

@implementation SPPartnerInfoViewController
@synthesize m_id;

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout=UIRectEdgeNone;
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    m_itemMutableArray = [[NSMutableArray alloc]init];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loginSuccess) name:NOTI_LOGIN_SUCC object:nil];
    
    [self loadInfoView];
    
    //segmentation control
    NSArray *Segmentarray = [[NSArray alloc]initWithObjects:@"我的合伙人列表",@"一级合伙人详情",@"次级合伙人概况",nil];
    m_segmentControl = [[UISegmentedControl alloc]initWithItems:Segmentarray];
    [m_segmentControl setFrame:CGRectMake(0, m_userInfoView.frame.origin.y + m_userInfoView.frame.size.height,300, 30)];
    [m_segmentControl setCenter:CGPointMake(self.view.center.x, m_segmentControl.center.y)];
    m_segmentControl.segmentedControlStyle = UISegmentedControlStyleBezeled;
    [m_segmentControl addTarget:self action:@selector(segPressed:) forControlEvents:UIControlEventValueChanged];
    m_segmentControl.selectedSegmentIndex = 1;
    [self.view addSubview:m_segmentControl];
    
    [self loadFirstPartnerView];

    [self loadSecondPartnerView];
    
    //partner table view
    CGRect frame = m_firstPartnerView.frame;
    frame.size.height = self.view.frame.size.height - frame.origin.y -44;
    m_partnerTableView = [[UITableView alloc]initWithFrame:frame];
    m_partnerTableView.delegate = self;
    m_partnerTableView.dataSource = self;
    //m_partnerTableView.separatorStyle = UITableViewCellSeparatorStyleNone;

    [self.view addSubview:m_firstPartnerView];
    
    [self getPartnerInfo];
}

- (void)loginSuccess{
    [self getPartnerInfo];
}

- (void)segPressed:(id)sender {
    NSInteger selectedSegment = m_segmentControl.selectedSegmentIndex;
    if (selectedSegment == 0) {
        [self.view addSubview:m_partnerTableView];
        if ([[self.view subviews] containsObject:m_secondPartnerView]) {
            [m_secondPartnerView removeFromSuperview];
        }
        if ([[self.view subviews] containsObject:m_firstPartnerView]) {
            [m_firstPartnerView removeFromSuperview];
        }
    }
    else if (selectedSegment == 1){
        [self.view addSubview:m_firstPartnerView];
        if ([[self.view subviews] containsObject:m_secondPartnerView]) {
            [m_secondPartnerView removeFromSuperview];
        }
        if ([[self.view subviews] containsObject:m_partnerTableView]) {
            [m_partnerTableView removeFromSuperview];
        }
    }
    else{
        [self.view addSubview:m_secondPartnerView];
        if ([[self.view subviews] containsObject:m_firstPartnerView]) {
            [m_firstPartnerView removeFromSuperview];
        }
        if ([[self.view subviews] containsObject:m_partnerTableView]) {
            [m_partnerTableView removeFromSuperview];
        }
    }
}

- (void)loadInfoView{
    //user info view
    m_userInfoView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 260)];
    [self.view addSubview:m_userInfoView];
    
    m_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 10, 300, 20)];
    [m_titleLabel setFont:[UIFont boldSystemFontOfSize:16]];
    [m_titleLabel setBackgroundColor:[UIColor clearColor]];
    [m_userInfoView addSubview:m_titleLabel];
    
    m_avatarImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 40, 40)];
    [m_avatarImageView setImage:[UIImage imageNamed:@"avatar"]];
    [m_userInfoView addSubview:m_avatarImageView];
    
    int xOffset = m_avatarImageView.frame.origin.x + m_avatarImageView.frame.size.width + 10;
    m_userInfoTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, 10, self.view.frame.size.width - xOffset - 20 , 45)];
    [m_userInfoTextLabel setFont:[UIFont systemFontOfSize:15]];
    [m_userInfoTextLabel setBackgroundColor:[UIColor clearColor]];
    [m_userInfoTextLabel setText:@"会员ID：      昵称："];
    [m_userInfoView addSubview:m_userInfoTextLabel];
    
    m_rankInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, m_userInfoTextLabel.frame.origin.y + m_userInfoTextLabel.frame.size.height, self.view.frame.size.width - xOffset - 20 , 45)];
    [m_rankInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_rankInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_rankInfoLabel setText:@"等级："];
    [m_userInfoView addSubview:m_rankInfoLabel];
    
    xOffset = 30;
    m_signinTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, m_rankInfoLabel.frame.origin.y + m_rankInfoLabel.frame.size.height , self.view.frame.size.width - xOffset - 20 , 30)];
    [m_signinTextLabel setFont:[UIFont systemFontOfSize:15]];
    [m_signinTextLabel setBackgroundColor:[UIColor clearColor]];
    [m_signinTextLabel setText:@"注册                         最后登录"];
    [m_userInfoView addSubview:m_signinTextLabel];
    
    m_signinInfoTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, m_signinTextLabel.frame.origin.y + m_signinTextLabel.frame.size.height -5 , self.view.frame.size.width - xOffset - 20 , 30)];
    [m_signinInfoTextLabel setFont:[UIFont systemFontOfSize:12]];
    [m_signinInfoTextLabel setBackgroundColor:[UIColor clearColor]];
    [m_signinInfoTextLabel setText:@""];
    [m_userInfoView addSubview:m_signinInfoTextLabel];
    
    xOffset = 25;
    m_detailTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, m_signinInfoTextLabel.frame.origin.y + m_signinInfoTextLabel.frame.size.height -5, self.view.frame.size.width - xOffset - 20 , 30)];
    [m_detailTextLabel setFont:[UIFont systemFontOfSize:15]];
    [m_detailTextLabel setBackgroundColor:[UIColor clearColor]];
    [m_detailTextLabel setText:@"本月收益          距离升级"];
    [m_userInfoView addSubview:m_detailTextLabel];
    
    m_detailInfoTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, m_detailTextLabel.frame.origin.y + m_detailTextLabel.frame.size.height -5, self.view.frame.size.width - xOffset - 20 , 30)];
    [m_detailInfoTextLabel setFont:[UIFont systemFontOfSize:15]];
    [m_detailInfoTextLabel setBackgroundColor:[UIColor clearColor]];
    [m_detailInfoTextLabel setText:@"..."];
    [m_userInfoView addSubview:m_detailInfoTextLabel];
    
    UILabel * m_partnerTextLable = [[UILabel alloc]initWithFrame:CGRectMake(30, m_detailInfoTextLabel.frame.origin.y + m_detailInfoTextLabel.frame.size.height , 80 , 30)];
    [m_partnerTextLable setFont:[UIFont systemFontOfSize:15]];
    [m_partnerTextLable setBackgroundColor:[UIColor clearColor]];
    [m_partnerTextLable setText:@"合伙人"];
    [m_userInfoView addSubview:m_partnerTextLable];
    
    m_partnerInfoLable = [[UILabel alloc]initWithFrame:CGRectMake(m_partnerTextLable.frame.origin.x, m_partnerTextLable.frame.origin.y + m_partnerTextLable.frame.size.height , 100 , 30)];
    [m_partnerInfoLable setFont:[UIFont systemFontOfSize:15]];
    [m_partnerInfoLable setBackgroundColor:[UIColor clearColor]];
    [m_partnerInfoLable setText:@"120"];
    [m_userInfoView addSubview:m_partnerInfoLable];
    
    m_firstPartnerInfoLable = [[UILabel alloc]initWithFrame:CGRectMake(m_partnerTextLable.frame.origin.x + m_partnerTextLable.frame.size.width + 20, m_partnerTextLable.frame.origin.y , 200 , 30)];
    [m_firstPartnerInfoLable setFont:[UIFont systemFontOfSize:15]];
    [m_firstPartnerInfoLable setBackgroundColor:[UIColor clearColor]];
    [m_firstPartnerInfoLable setText:@"一级合伙人：60人"];
    [m_userInfoView addSubview:m_firstPartnerInfoLable];
    
    m_secondPartnerInfoLable = [[UILabel alloc]initWithFrame:CGRectMake(m_firstPartnerInfoLable.frame.origin.x, m_firstPartnerInfoLable.frame.origin.y + m_firstPartnerInfoLable.frame.size.height , 200 , 30)];
    [m_secondPartnerInfoLable setFont:[UIFont systemFontOfSize:15]];
    [m_secondPartnerInfoLable setBackgroundColor:[UIColor clearColor]];
    [m_secondPartnerInfoLable setText:@"二级合伙人：60人"];
    [m_userInfoView addSubview:m_secondPartnerInfoLable];
    
    CGRect frame = m_userInfoView.frame;
    frame.size.height = m_secondPartnerInfoLable.frame.origin.y + m_secondPartnerInfoLable.frame.size.height;
    m_userInfoView.frame = frame;
}

- (void)loadFirstPartnerView{
    //first partner view
    m_firstPartnerView = [[UIView alloc]initWithFrame:CGRectMake(0, m_segmentControl.frame.origin.y + m_segmentControl.frame.size.height + 10, self.view.frame.size.width, 200)];
    
    UILabel * firstTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0 , 150 , 30)];
    [firstTitleLabel setFont:[UIFont systemFontOfSize:15]];
    [firstTitleLabel setBackgroundColor:[UIColor clearColor]];
    [firstTitleLabel setText:@"一级合伙人概况"];
    [m_firstPartnerView addSubview:firstTitleLabel];
    
    int xOffset = 20;
    UILabel * firstPartnerAmountLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, 50 , 60 , 30)];
    [firstPartnerAmountLabel setFont:[UIFont systemFontOfSize:15]];
    [firstPartnerAmountLabel setBackgroundColor:[UIColor clearColor]];
    [firstPartnerAmountLabel setText:@"人数"];
    [m_firstPartnerView addSubview:firstPartnerAmountLabel];
    
    m_firstPartnerAmountInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(firstPartnerAmountLabel.frame.origin.x, firstPartnerAmountLabel.frame.origin.y + firstPartnerAmountLabel.frame.size.height , 60 , 30)];
    [m_firstPartnerAmountInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_firstPartnerAmountInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_firstPartnerAmountInfoLabel setText:@"..."];
    [m_firstPartnerView addSubview:m_firstPartnerAmountInfoLabel];
    
    UILabel * firstPartnerContributionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width - xOffset-60,firstPartnerAmountLabel.frame.origin.y, 60 , 30)];
    [firstPartnerContributionLabel setFont:[UIFont systemFontOfSize:15]];
    [firstPartnerContributionLabel setBackgroundColor:[UIColor clearColor]];
    [firstPartnerContributionLabel setText:@"对您贡献"];
    [m_firstPartnerView addSubview:firstPartnerContributionLabel];
    
    m_firstPartnerContributionInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(firstPartnerContributionLabel.frame.origin.x, firstPartnerContributionLabel.frame.origin.y + firstPartnerContributionLabel.frame.size.height , 60 , 30)];
    [m_firstPartnerContributionInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_firstPartnerContributionInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_firstPartnerContributionInfoLabel setText:@"182"];
    [m_firstPartnerView addSubview:m_firstPartnerContributionInfoLabel];
    
    xOffset = 70;
    UILabel * firstPartnerInLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, 20 , 70 , 30)];
    [firstPartnerInLabel setFont:[UIFont systemFontOfSize:15]];
    [firstPartnerInLabel setBackgroundColor:[UIColor clearColor]];
    [firstPartnerInLabel setText:@"股票配资"];
    [m_firstPartnerView addSubview:firstPartnerInLabel];
    
    UILabel * firstPartnerIn2Label = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width-xOffset-80, firstPartnerInLabel.frame.origin.y , 70 , 30)];
    [firstPartnerIn2Label setFont:[UIFont systemFontOfSize:15]];
    [firstPartnerIn2Label setBackgroundColor:[UIColor clearColor]];
    [firstPartnerIn2Label setText:@"期货配资"];
    [m_firstPartnerView addSubview:firstPartnerIn2Label];
    
    m_firstPartnerInInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(firstPartnerInLabel.frame.origin.x, firstPartnerInLabel.frame.origin.y +30 , 160 , 30)];
    [m_firstPartnerInInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_firstPartnerInInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_firstPartnerInInfoLabel setText:@"..."];
    [m_firstPartnerView addSubview:m_firstPartnerInInfoLabel];
    
    m_firstPartnerIn2InfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(firstPartnerIn2Label.frame.origin.x, firstPartnerIn2Label.frame.origin.y +30 , 160 , 30)];
    [m_firstPartnerIn2InfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_firstPartnerIn2InfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_firstPartnerIn2InfoLabel setText:@"..."];
    [m_firstPartnerView addSubview:m_firstPartnerIn2InfoLabel];
    
    UILabel * firstPartnerOutLabel = [[UILabel alloc]initWithFrame:CGRectMake(firstPartnerInLabel.frame.origin.x, firstPartnerInLabel.frame.origin.y + 60 , firstPartnerInLabel.frame.size.width , 30)];
    [firstPartnerOutLabel setFont:[UIFont systemFontOfSize:15]];
    [firstPartnerOutLabel setBackgroundColor:[UIColor clearColor]];
    [firstPartnerOutLabel setText:@"股票返佣"];
    [m_firstPartnerView addSubview:firstPartnerOutLabel];
    
    UILabel * firstPartnerOut2Label = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width-xOffset-80, firstPartnerInLabel.frame.origin.y + 60 , firstPartnerInLabel.frame.size.width , 30)];
    [firstPartnerOut2Label setFont:[UIFont systemFontOfSize:15]];
    [firstPartnerOut2Label setBackgroundColor:[UIColor clearColor]];
    [firstPartnerOut2Label setText:@"期货返佣"];
    [m_firstPartnerView addSubview:firstPartnerOut2Label];
    
    m_firstPartnerOutInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(firstPartnerOutLabel.frame.origin.x, firstPartnerOutLabel.frame.origin.y +30 , 160 , 30)];
    [m_firstPartnerOutInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_firstPartnerOutInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_firstPartnerOutInfoLabel setText:@"10000"];
    [m_firstPartnerView addSubview:m_firstPartnerOutInfoLabel];
    
    m_firstPartnerOut2InfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(firstPartnerOut2Label.frame.origin.x, firstPartnerOutLabel.frame.origin.y +30 , 160 , 30)];
    [m_firstPartnerOut2InfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_firstPartnerOut2InfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_firstPartnerOut2InfoLabel setText:@"10000"];
    [m_firstPartnerView addSubview:m_firstPartnerOut2InfoLabel];
}

- (void)loadSecondPartnerView{
    //second partner view
    m_secondPartnerView = [[UIView alloc]initWithFrame:m_firstPartnerView.frame];
    
    UILabel * secondTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 0 , 150 , 30)];
    [secondTitleLabel setFont:[UIFont systemFontOfSize:15]];
    [secondTitleLabel setBackgroundColor:[UIColor clearColor]];
    [secondTitleLabel setText:@"次级合伙人概况"];
    [m_secondPartnerView addSubview:secondTitleLabel];
    
    int xOffset = 20;
    UILabel * secondPartnerAmountLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, 50 , 60 , 30)];
    [secondPartnerAmountLabel setFont:[UIFont systemFontOfSize:15]];
    [secondPartnerAmountLabel setBackgroundColor:[UIColor clearColor]];
    [secondPartnerAmountLabel setText:@"人数"];
    [m_secondPartnerView addSubview:secondPartnerAmountLabel];
    
    m_secondPartnerAmountInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(secondPartnerAmountLabel.frame.origin.x, secondPartnerAmountLabel.frame.origin.y + secondPartnerAmountLabel.frame.size.height , 60 , 30)];
    [m_secondPartnerAmountInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_secondPartnerAmountInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_secondPartnerAmountInfoLabel setText:@"182"];
    [m_secondPartnerView addSubview:m_secondPartnerAmountInfoLabel];
    
    UILabel * secondPartnerContributionLabel = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width - xOffset-60,secondPartnerAmountLabel.frame.origin.y, 60 , 30)];
    [secondPartnerContributionLabel setFont:[UIFont systemFontOfSize:15]];
    [secondPartnerContributionLabel setBackgroundColor:[UIColor clearColor]];
    [secondPartnerContributionLabel setText:@"对您贡献"];
    [m_secondPartnerView addSubview:secondPartnerContributionLabel];
    
    m_secondPartnerContributionInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(secondPartnerContributionLabel.frame.origin.x, secondPartnerContributionLabel.frame.origin.y + secondPartnerContributionLabel.frame.size.height , 60 , 30)];
    [m_secondPartnerContributionInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_secondPartnerContributionInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_secondPartnerContributionInfoLabel setText:@"182"];
    [m_secondPartnerView addSubview:m_secondPartnerContributionInfoLabel];
    
    xOffset = 70;
    UILabel * secondPartnerInLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, 20 , 70 , 30)];
    [secondPartnerInLabel setFont:[UIFont systemFontOfSize:15]];
    [secondPartnerInLabel setBackgroundColor:[UIColor clearColor]];
    [secondPartnerInLabel setText:@"股票配资"];
    [m_secondPartnerView addSubview:secondPartnerInLabel];
    
    UILabel * secondPartnerIn2Label = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width-xOffset-80, secondPartnerInLabel.frame.origin.y , 70 , 30)];
    [secondPartnerIn2Label setFont:[UIFont systemFontOfSize:15]];
    [secondPartnerIn2Label setBackgroundColor:[UIColor clearColor]];
    [secondPartnerIn2Label setText:@"期货配资"];
    [m_secondPartnerView addSubview:secondPartnerIn2Label];
    
    m_secondPartnerInInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(secondPartnerInLabel.frame.origin.x, secondPartnerInLabel.frame.origin.y +30 , 160 , 30)];
    [m_secondPartnerInInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_secondPartnerInInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_secondPartnerInInfoLabel setText:@"10000"];
    [m_secondPartnerView addSubview:m_secondPartnerInInfoLabel];
    
    m_secondPartnerIn2InfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(secondPartnerIn2Label.frame.origin.x, secondPartnerIn2Label.frame.origin.y +30 , 160 , 30)];
    [m_secondPartnerIn2InfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_secondPartnerIn2InfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_secondPartnerIn2InfoLabel setText:@"10000"];
    [m_secondPartnerView addSubview:m_secondPartnerIn2InfoLabel];
    
    UILabel * secondPartnerOutLabel = [[UILabel alloc]initWithFrame:CGRectMake(secondPartnerInLabel.frame.origin.x, secondPartnerInLabel.frame.origin.y + 60 , secondPartnerInLabel.frame.size.width , 30)];
    [secondPartnerOutLabel setFont:[UIFont systemFontOfSize:15]];
    [secondPartnerOutLabel setBackgroundColor:[UIColor clearColor]];
    [secondPartnerOutLabel setText:@"股票返佣"];
    [m_secondPartnerView addSubview:secondPartnerOutLabel];
    
    UILabel * secondPartnerOut2Label = [[UILabel alloc]initWithFrame:CGRectMake(self.view.frame.size.width-xOffset-80, secondPartnerInLabel.frame.origin.y + 60 , secondPartnerInLabel.frame.size.width , 30)];
    [secondPartnerOut2Label setFont:[UIFont systemFontOfSize:15]];
    [secondPartnerOut2Label setBackgroundColor:[UIColor clearColor]];
    [secondPartnerOut2Label setText:@"期货返佣"];
    [m_secondPartnerView addSubview:secondPartnerOut2Label];
    
    m_secondPartnerOutInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(secondPartnerOutLabel.frame.origin.x, secondPartnerOutLabel.frame.origin.y +30 , 160 , 30)];
    [m_secondPartnerOutInfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_secondPartnerOutInfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_secondPartnerOutInfoLabel setText:@"10000"];
    [m_secondPartnerView addSubview:m_secondPartnerOutInfoLabel];
    
    m_secondPartnerOut2InfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(secondPartnerOut2Label.frame.origin.x, secondPartnerOutLabel.frame.origin.y +30 , 160 , 30)];
    [m_secondPartnerOut2InfoLabel setFont:[UIFont systemFontOfSize:15]];
    [m_secondPartnerOut2InfoLabel setBackgroundColor:[UIColor clearColor]];
    [m_secondPartnerOut2InfoLabel setText:@"10000"];
    [m_secondPartnerView addSubview:m_secondPartnerOut2InfoLabel];
}

- (void)getPartnerInfo{
    SPHTTPRequestOperationManager *manager = [SPHTTPRequestOperationManager manager];
    [manager getPartnersInfoWithID:USER_ID Success:^(AFHTTPRequestOperation *operation, id responseObject) {
        responseObject = [Methods safeResponseObj:responseObject];
        NSLog(@"get_partner_info>>>>>>>>SUCCESS: %@",responseObject);
        [m_userInfoTextLabel setText:[NSString stringWithFormat:@"会员ID：%@  昵称：%@",USER_ID,NICK_NAME]];
        [m_rankInfoLabel setText:[NSString stringWithFormat:@"等级：%@",[[responseObject objectForKey:@"statinfo"] valueForKey:@"hhr_level"]]];
        [m_signinInfoTextLabel setText:[NSString stringWithFormat:@"%@     %@",[[responseObject objectForKey:@"userinfo"] valueForKey:@"register_time"],[[responseObject objectForKey:@"userinfo"] valueForKey:@"last_login_time"]]];
        [m_detailInfoTextLabel setText:[NSString stringWithFormat:@"%@",[[responseObject objectForKey:@"statinfo"] valueForKey:@"monthly_income"]]];
        [m_firstPartnerInfoLable setText:[NSString stringWithFormat:@"一级合伙人：%@",[[responseObject objectForKey:@"statinfo"] valueForKey:@"firstly_partner_num"]]];
        [m_secondPartnerInfoLable setText:[NSString stringWithFormat:@"二级合伙人：%@",[[responseObject objectForKey:@"statinfo"] valueForKey:@"secondary_partner_num"]]];
        int sum = [m_firstPartnerInfoLable.text intValue] +  [m_secondPartnerInfoLable.text intValue];
        [m_partnerInfoLable setText:[NSString stringWithFormat:@"%d",sum]];
        
        [m_firstPartnerAmountInfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"firstly_partner_num"]];
        [m_firstPartnerInInfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"firstly_stock_endowment"]];
        [m_firstPartnerIn2InfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"firstly_futures_endowment"]];
        [m_firstPartnerOutInfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"firstly_stock_commission"]];
        [m_firstPartnerOut2InfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"firstly_futures_commission"]];
        [m_firstPartnerContributionInfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"firstly_contribution_income"]];
        
        [m_secondPartnerAmountInfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"secondary_partner_num"]];
        [m_secondPartnerInInfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"secondary_stock_endowment"]];
        [m_secondPartnerIn2InfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"secondary_futures_endowment"]];
        [m_secondPartnerOutInfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"secondary_stock_commission"]];
        [m_secondPartnerOut2InfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"secondary_futures_commission"]];
        [m_secondPartnerContributionInfoLabel setText:[[responseObject objectForKey:@"statinfo"] valueForKey:@"secondary_contribution_income"]];
        
        m_itemMutableArray = [[NSMutableArray alloc]initWithArray:[responseObject objectForKey:@"partners"]];
        [m_partnerTableView reloadData];
        
    }failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"get_partner_info>>>>>>>>Error: %@", error);
    }];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    // Return the number of rows in the section.
    return [m_itemMutableArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 54.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    NSDictionary * dataDic = [m_itemMutableArray objectAtIndex:indexPath.row];
    
    PartnerCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
    if (cell == nil) {
        cell = [[PartnerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"];
    }
    [cell setCellInfo:dataDic];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary * dataDic = [m_itemMutableArray objectAtIndex:indexPath.row];
    
    SPSecondPartnerInfoViewController * vc = [[SPSecondPartnerInfoViewController alloc]init];
    vc.m_id = [dataDic valueForKey:@"id"];
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
}

@end

@implementation PartnerCell
@synthesize m_titleLabel;
@synthesize m_avatarImageView;
@synthesize m_userInfoTextLabel;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];
        
        m_titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(15, 10, 300, 20)];
        [m_titleLabel setFont:[UIFont boldSystemFontOfSize:16]];
        [m_titleLabel setBackgroundColor:[UIColor clearColor]];
        [self addSubview:m_titleLabel];
        
//        m_avatarImageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 10, 40, 40)];
//        [m_avatarImageView setImage:[UIImage imageNamed:@"avatar"]];
//        [self addSubview:m_avatarImageView];
        
        int xOffset = 10;
        UILabel * userInfoLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, 3, self.frame.size.width - xOffset , 25)];
        [userInfoLabel setFont:[UIFont systemFontOfSize:13]];
        [userInfoLabel setBackgroundColor:[UIColor clearColor]];
        [userInfoLabel setText:@"姓名     合伙人     本月收益     本月配资     对您贡献"];
        [self addSubview:userInfoLabel];
        
        m_userInfoTextLabel = [[UILabel alloc]initWithFrame:CGRectMake(xOffset, userInfoLabel.frame.origin.y + userInfoLabel.frame.size.height, self.frame.size.width - xOffset , 25)];
        [m_userInfoTextLabel setFont:[UIFont systemFontOfSize:13]];
        [m_userInfoTextLabel setBackgroundColor:[UIColor clearColor]];
        [m_userInfoTextLabel setText:@"姓名："];
        [self addSubview:m_userInfoTextLabel];
        
     
//        UIView * backColorView = [[UIView alloc]initWithFrame:CGRectMake(0, m_signinInfoTextLabel.frame.origin.y + m_signinInfoTextLabel.frame.size.height+5, self.frame.size.width, 15)];
//        [backColorView setBackgroundColor:[UIColor colorWithRed:239.0/255.0 green:239.0/255.0 blue:244.0/255.0 alpha:1.0]];
//        [self addSubview:backColorView];
//        
//        UIView * backLineView = [[UIView alloc]initWithFrame:CGRectMake(0, m_signinInfoTextLabel.frame.origin.y + m_signinInfoTextLabel.frame.size.height+5, self.frame.size.width, 1)];
//        [backLineView setBackgroundColor:[UIColor colorWithRed:229.0/255.0 green:229.0/255.0 blue:234.0/255.0 alpha:1.0]];
//        [self addSubview:backLineView];
        
        self.selectionStyle = UITableViewCellSelectionStyleGray;
    }
    return self;
}

- (void)setImageView:(UIImage*)image
{
    m_avatarImageView.image = image;
    [m_avatarImageView setFrame:CGRectMake(20, 10, 40 , 40)];
}

- (void)setImageUrl:(NSString *)urlStr{
    //NSURL * url = [NSURL URLWithString:[[BASED_URL stringByAppendingString:@"/"] stringByAppendingString:urlStr]];
    //[m_imageView setImageWithURL:url placeholderImage:[UIImage imageNamed:@"food_loading"]];
}

- (void)setCellInfo:(NSDictionary *)info{
    int sum = [[info valueForKey:@"firstly_partner_num"] intValue] + [[info valueForKey:@"firstly_partner_num"] intValue];
    [m_userInfoTextLabel setText:[NSString stringWithFormat:@"%@            %@                  *                %@              *",[info valueForKey:@"account_name"],[NSString stringWithFormat:@"%d",sum],[info valueForKey:@"monthly_stock_endowment"]]];
}
@end
